package cn.youth996.nav.controller;

import cn.youth996.nav.domain.GeoPoint;
import cn.youth996.nav.dto.GeoPointDTO;
import cn.youth996.nav.service.GeoPointService;
import cn.youth996.nav.util.PageUtils;
import cn.youth996.nav.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 地理坐标信息
 *
 * @author Zhan Xinjian
 * @date 2025/7/10
 */
@RestController
@RequestMapping("/geo/point")
@Api(tags = "地理坐标信息管理")
public class GeoPointController {
    @Autowired
    private GeoPointService geoPointService;
    /**
     * 分页
     *
     * @param params 分页参数
     * @return 分页数据
     */
    @GetMapping("/page")
    @ApiOperation("分页")
    public Result<PageUtils> page(@RequestParam Map<String, Object> params) {
        PageUtils page = geoPointService.queryPage(params);
        return new Result<PageUtils>().ok(page);
    }

    /**
     * 列表
     *
     * @param params 列表参数
     * @return 列表数据
     */
    @GetMapping("/list")
    @ApiOperation("列表")
    public Result<List<GeoPoint>> list(@RequestParam Map<String, Object> params) {
        List<GeoPoint> list = geoPointService.list(params);
        return new Result<List<GeoPoint>>().ok(list);
    }

    /**
     * 信息
     *
     * @param id id
     * @return 响应结果
     */
    @GetMapping("/info/{id}")
    @ApiOperation("信息")
    public Result<GeoPoint> info(@PathVariable("id") Integer id) {
        return new Result<GeoPoint>().ok(geoPointService.getById(id));
    }

    /**
     * 保存
     *
     * @param domain 表单数据
     * @return 响应结果
     */
    @PostMapping("/save")
    @ApiOperation("保存")
    public synchronized Result save(@Validated @RequestBody GeoPoint domain) {
        geoPointService.save(domain);
        return new Result();
    }


    /**
     * 保存
     *
     * @param dto 表单数据
     * @return 响应结果
     */
    @PostMapping("/saveWithPic")
    @ApiOperation("保存")
    public synchronized Result saveWithPic(@Validated @RequestBody GeoPointDTO dto) {
        geoPointService.saveWithPic(dto);
        return new Result();
    }

    /**
     * 修改
     *
     * @param domain 表单数据
     * @return 响应结果
     */
    @PostMapping("/update")
    @ApiOperation("修改")
    public Result update(@Validated @RequestBody GeoPoint domain) {
        geoPointService.updateById(domain);
        return new Result();
    }

    /**
     * 修改
     *
     * @param dto 表单数据
     * @return 响应结果
     */
    @PostMapping("/updateWithPic")
    @ApiOperation("修改")
    public Result updateWithPic(@Validated @RequestBody GeoPointDTO dto) {
        geoPointService.updateWithPic(dto);
        return new Result();
    }

    /**
     * 删除
     *
     * @param ids id数组
     * @return 响应结果
     */
    @PostMapping("/delete/{ids}")
    @ApiOperation("删除")
    public Result delete(@PathVariable Long[] ids) {
        /*根据id获取*/
        geoPointService.removeByIds(Arrays.asList(ids));
        return new Result();
    }
}
